package com.shenjian.settings.controller;

import com.shenjian.commons.utils.Result;
import com.shenjian.settings.entity.DicType;
import com.shenjian.settings.service.DicTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * (DicType)表控制层
 *
 * @author makejava
 * @since 2022-06-29 15:30:46
 */
@RestController
@RequestMapping("/dicType")
public class DicTypeController {
    /**
     * 服务对象
     */
    @Autowired
    private DicTypeService dicTypeService;

    /**
     * 分页查询
     *
     * @param pageNumber 当前页码
     * @param pageSize 每页条数
     * @param dicType 筛选条件
     * @return 查询结果
     */
    @GetMapping("/page")
    public Result listPage(@RequestParam(value = "pageNumber", defaultValue = "1") Integer pageNumber, @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize, DicType dicType) {
        return Result.success(dicTypeService.listPage(pageNumber, pageSize, dicType));
    }

    /**
     * 查询全部
     * @return
     */
    @GetMapping("/list")
    public Result list(){
        return Result.success(dicTypeService.list());
    }

    /**
     * 通过主键查询单条数据
     *
     * @param code 主键
     * @return 单条数据
     */
    @GetMapping("/find/{code}")
    public Result findById(@PathVariable("code") String code) {
        return Result.success(dicTypeService.findById(code));
    }

    /**
     * 新增数据
     *
     * @param dicType 实体
     * @return 新增结果
     */
    @PostMapping("/save")
    public Result add(@RequestBody DicType dicType) {
        return Result.success(dicTypeService.save(dicType));
    }

    /**
     * 编辑数据
     *
     * @param dicType 实体
     * @return 编辑结果
     */
    @PutMapping("/edit")
    public Result edit(@RequestBody DicType dicType) {
        return Result.success(dicTypeService.edit(dicType));
    }

    /**
     * 删除数据
     *
     * @param code 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/remove/{code}")
    public Result remove(@PathVariable("code") String code) {
        return Result.success(dicTypeService.remove(code));
    }
    /**
     * 删除数据
     *
     * @param ids 主键数组
     * @return 删除是否成功
     */
    @DeleteMapping("/remove")
    public Result removeBatch(String[] ids) {
        return Result.success(dicTypeService.removeBatch(ids));
    }

}

